﻿<UserControl x:Class="GSF.TimeSeries.UI.UserControls.MeasurementPagerUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:uc="clr-namespace:GSF.TimeSeries.UI.UserControls"
             xmlns:tsf="clr-namespace:GSF.TimeSeries.UI"
             d:DesignHeight="300" d:DesignWidth="500" Name="MeasurementPager"
             Loaded="MeasurementPager_Loaded" Unloaded="MeasurementPager_Unloaded"
             KeyDown="MeasurementPagerUserControl_KeyDown">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/GSF.TimeSeries.UI.WPF;Component/Resources/CommonResource.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Name="RootPanel" Orientation="Vertical">
        <DockPanel>
            <Label DockPanel.Dock="Left" Name="SelectedMeasurementsLabel" Content="Selected: 0" Visibility="{Binding ElementName=MeasurementPager, Path=Selectable, Converter={StaticResource ObjectToVisibilityConverter}}" />

            <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right" Visibility="{Binding ElementName=MeasurementPager, Path=Searchable, Converter={StaticResource ObjectToVisibilityConverter}}">
                <TextBox Name="SearchTextBox" Text="{Binding Mode=TwoWay, Path=SearchText, UpdateSourceTrigger=PropertyChanged}" Width="150" KeyDown="SearchTextBox_KeyDown" />
                <Button Content="Search" Command="{Binding Path=SearchCommand}" ToolTip="Search measurements" Margin="2" />
                <Button Content="Advanced..." Command="{Binding Path=AdvancedFindCommand}" ToolTip="Opens advanced find dialog" Margin="2"/>
            </StackPanel>
        </DockPanel>

        <Button Name="SelectAllHyperlink" Width="Auto" Content="Click here to select all measurements on all pages." HorizontalAlignment="Left" Visibility="Collapsed" Template="{StaticResource HyperlinkStyleButtonTemplate}" Click="SelectAllHyperlink_Click" Margin="0" />

        <DataGrid x:Name="DataGridList" ItemsSource="{Binding CurrentPage}" SelectedItem="{Binding Path=CurrentItem, Mode=TwoWay}" Height="Auto" Sorting="DataGrid_Sorting" IsReadOnly="True" LoadingRow="DataGridList_LoadingRow" SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Visible">
            <DataGrid.Columns>
                <DataGridTemplateColumn Width="50" Visibility="Collapsed">
                    <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <CheckBox Name="SelectAllCheckBox" Click="SelectAllCheckBox_Click" ToolTip="Click to select all." />
                        </DataTemplate>
                    </DataGridTemplateColumn.HeaderTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox Name="ItemCheckBox" HorizontalAlignment="Center" Margin="0" Click="ItemCheckBox_Click" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Width="60" Header="ID" Binding="{Binding ID}" ToolTipService.IsEnabled="True" >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                            <Setter Property="ToolTip" Value="{Binding ID}" />
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Width="200" Header="Point Tag" Binding="{Binding Path=PointTag, Converter={StaticResource PointTagConverter}}" ToolTipService.IsEnabled="True" >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                            <Setter Property="ToolTip" Value="{Binding PointTag}" />
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Width="Auto" Header="Description" Binding="{Binding Description}" />
            </DataGrid.Columns>
        </DataGrid>

        <uc:DataPagerUserControl x:Name="DataPager" CurrentPageNumber="{Binding CurrentPageNumber}" PageCount="{Binding PageCount}"
                                 FirstCommand="{Binding FirstCommand}" PreviousCommand="{Binding PreviousCommand}"
                                 NextCommand="{Binding NextCommand}" LastCommand="{Binding LastCommand}"/>

        <tsf:TsfPopup x:Name="AdvancedFindPopup" Placement="Center" Width="500" Height="350" Topmost="False" Visibility="Collapsed" IsOpen="{Binding AdvancedFindIsOpen}">
            <Border CornerRadius="5" BorderThickness="2" Background="White" BorderBrush="Blue">
                <Grid Margin="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <uc:AdvancedSearchUserControl Grid.Row="0" x:Name="AdvancedSearch" SearchText="{Binding Mode=TwoWay, Path=SearchText}" IgnoreCase="{Binding Mode=TwoWay, Path=IgnoreCase}" UseWildcards="{Binding Mode=TwoWay, Path=UseWildcards}" UseRegex="{Binding Mode=TwoWay, Path=UseRegex}">
                        <uc:AdvancedSearchUserControl.Categories>
                            <uc:AdvancedSearchCategory Name="CompanyAcronym" />
                            <uc:AdvancedSearchCategory Name="CompanyName" />
                            <uc:AdvancedSearchCategory Name="Description" />
                            <uc:AdvancedSearchCategory Name="DeviceAcronym" />
                            <uc:AdvancedSearchCategory Name="HistorianAcronym" />
                            <uc:AdvancedSearchCategory Name="ID" />
                            <uc:AdvancedSearchCategory Name="PhasorLabel" />
                            <uc:AdvancedSearchCategory Name="PointTag" />
                            <uc:AdvancedSearchCategory Name="SignalAcronym" />
                            <uc:AdvancedSearchCategory Name="SignalID" />
                            <uc:AdvancedSearchCategory Name="SignalName" />
                            <uc:AdvancedSearchCategory Name="SignalReference" />
                            <uc:AdvancedSearchCategory Name="SignalSuffix" />
                        </uc:AdvancedSearchUserControl.Categories>
                    </uc:AdvancedSearchUserControl>

                    <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
                        <Button Content="Search" Command="{Binding SearchCommand}" Width="Auto" Margin="5" IsDefault="True" />
                        <Button Content="Cancel" Command="{Binding CloseAdvancedFindCommand}" Width="Auto" Margin="5" IsCancel="True" />
                    </StackPanel>
                </Grid>
            </Border>
        </tsf:TsfPopup>
    </StackPanel>
</UserControl>
